package com.hschinese.pronunciation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hschinese.pronunciation.R;

import java.util.List;

/**
 * Created by wo on 2015/11/9.
 */
public class ConsonantsGridViewAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    private Context mContext = null;
    private List<String> mData = null;

    public ConsonantsGridViewAdapter(Context context, List<String> data) {
        inflater = LayoutInflater.from(context);
        mContext = context;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public String getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.consonants_gridview_item, parent, false);
            holder = new ViewHolder();
            holder.textView = (TextView)convertView.findViewById(R.id.consonants_gridview_item_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        if (mData != null) {
            holder.textView.setText(mData.get(position));
        }
        return convertView;
    }

    class ViewHolder {
        public TextView textView;
    }
}
